package com.icoolkj.learn.juc.future;

import com.icoolkj.learn.juc.base.utils.SleepTools;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.FutureTask;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/03/05 13:44
 */
@Slf4j
public class FutureDemo {

    @SneakyThrows
    public static void main(String[] args) {
        new Thread(() -> {
            log.info("通过 Runnable 方式执行任务");
        }, "t1").start();

        FutureTask<String> task = new FutureTask<>(() -> {
            log.info("通过 Callable 方式执行任务");
            SleepTools.second(3);
            return "返回任务结果";
        });

        new Thread(task, "t2").start();
        log.info("执行结果：{}", task.get());
    }
}
